home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 455 / samples / xarg.c < prev   
Encoding:
C/C++ Source or Header  |  1990-07-20  |  1.5 KB  |  59 lines

  1. /*
  2.  * xarg.c
  3.  * 10/10/88
  4.  * Sample implementation (in Turbo C) of a program, which gets its arguments
  5.  * via xArg, including legality checks.
  6.  */
  7.  
  8. #include <tos.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. typedef struct
  14. {
  15.    char      xarg_magic[4];   /* "xArg" == 0x78417267L */
  16.    int    xargc;           /* As argc in main()     */
  17.    char   **xargv;         /* As argv in main()     */
  18.    char   *xiovector;      /* Not used              */
  19.    BASPAG *xparent;        /* Points to the basepage of the     */
  20.                            /* caller. Type declaration in tos.h */
  21. } XARG;
  22.  
  23. main(void)
  24. {
  25.    extern BASPAG *_BasPag;   /* defined in TCSTART.O */
  26.    XARG   *xarg;
  27.    char *xenv;
  28.    unsigned long x;
  29.    int i;
  30.    
  31.    if ((xenv=getenv("xArg"))!=NULL)
  32.    {
  33.       x = strtoul(xenv,NULL,16);
  34.       printf("xArg structure at %08lX\n",x);
  35.       if ((x!=0) && (x%2==0))
  36.       {
  37.          xarg = (XARG *)x;
  38.          if (!strncmp(xarg->xarg_magic,"xArg",4))
  39.          {
  40.             if (xarg->xparent == _BasPag->p_parent)
  41.             {
  42.                /* Everything ok. Process arguments */
  43.                for (i=0; i<xarg->xargc; ++i)
  44.                   printf("%d: %s\n",i,xarg->xargv[i]);
  45.             }
  46.             else
  47.                printf("xArg parent != my parent\n");
  48.          }
  49.          else
  50.             printf("xArg magic number not found\n");
  51.       }
  52.       else
  53.          printf("illegal xArg address (0 or odd)\n");
  54.    }
  55.    else
  56.       printf("xArg not in environment\n");
  57.    return 0;
  58. }
  59.